const {app, BrowserWindow, Menu, MenuItem} = require('electron');
const path = require('path');

//Create native application menus and context menus.
//https://www.electronjs.org/docs/latest/api/menu

app.on('ready', () => {
  let win = new BrowserWindow({
    //https://www.electronjs.org/docs/latest/api/browser-window#new-browserwindowoptions
    width: 802,
    height: 550,

    webPreferences: {
      nodeIntegration: true,
      // contextIsolation: true,
      // enableRemoteModule: false,
      // devTools: true
    }
  });


  //todo 只对Menu.buildTemplate的有用 直接new Menu()的没用
  //You can make use of before, after, beforeGroupContaining, afterGroupContaining and id to control how the item will be placed when building a menu with Menu.buildFromTemplate.
  const template = [
    { id: '1', label: 'one' },
    { type: 'separator' },
    { id: '3', label: 'three', beforeGroupContaining: ['1'] },
    { type: 'separator' },
    { id: '4', label: 'four', afterGroupContaining: ['2'] },
    { type: 'separator' },
    { id: '2', label: 'two' }
  ]
  const menu = Menu.buildFromTemplate(template)
  Menu.setApplicationMenu(menu);

  menu.popup()

  win.loadFile(path.resolve(__dirname, 'index.html'))
});

